<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/7/1
 * Time: 8:33 AM
 */
namespace app\common\models;

use app\common\helpers\Cache;

class Plugin extends BaseModel
{
    public $table = 'yq_plugin';
    public $timestamps = false;
    protected $guarded = [''];
    //给客户单独开发的插件用cus_开头
    //用户自己开发的插件用dev_开头
    //这里限制只能四个字符
    //public static $localPre = ['cus_','dev_'];

    public static function getByName($name){
        return self::site()->select()
            ->where('name',$name)
            ->first();
    }
    public static function getEnabledList(){
        return self::site()->select()
            ->where('status',self::STATUS_NORMAL)
            ->get();
    }
    public static function getEnabledListCache(){
        $cacheKey = 'app:common:models:getEnabledListCache';
        if(Cache::has($cacheKey)){
            return Cache::get($cacheKey);
        }
        $list = self::getEnabledList();
        Cache::put($cacheKey,$list,60);
        return $list;
    }

    public static function getAllEnabledNameMap(){
        $list = self::getEnabledListCache();
        $res = [];
        foreach ($list as $v){
            $res[$v['name']] = $v;
        }
        return $res;
    }
    public static function clearAllCache(){
        Cache::forget('app:common:models:getEnabledListCache');
    }
}